﻿@using Telerik.Web.Mvc.UI
@using MvcFront.Models
@{
    ViewBag.Title = "Index";
}
    @Html.ValidationSummary(true)
<h2>Список групповых документов</h2>
@(Html.Telerik().Grid<DocumentListViewModel>()
            .DataBinding(dataBinding => dataBinding.Ajax().Select("_SendedGroupDocumentsList", "ManagerDocument", new { }))
        .Name("GroupDocumentListGrid")
                    .ClientEvents(events => events.OnRowDataBound("onDocumentListGridRowDataBound"))
                   .Columns(columns =>
                   {
                       columns.AutoGenerate(column =>
                       {
                           column.Width = "150px";
                           if (column.Member == "DocumentId" || column.Member == "IsReadOnly" || column.Member == "IsRed")
                               column.Visible = false;
                       });
                       columns.Command(command =>
                       {
                           command.Custom("viewDetails").Text("Просмотр")
                            .DataRouteValues(route => route.Add(o => o.DocumentId).RouteKey("docId"))
                            .Action("ViewDocumentDetails", "ManagerDocument")
                            .HtmlAttributes(new { style = "text-align: center" });
                       }).Width(50);
                   })

                 .Sortable()
                .Pageable()
                .Filterable()
                )

<h2>Список личных документов</h2>
@(Html.Telerik().Grid<DocumentListViewModel>()
            .DataBinding(dataBinding => dataBinding.Ajax().Select("_SendedUserDocumentsList", "ManagerDocument", new { }))
        .Name("UserDocumentListGrid")
                .ClientEvents(events => events.OnRowDataBound("onDocumentListGridRowDataBound"))
                   .Columns(columns =>
                   {
                       columns.AutoGenerate(column =>
                       {
                           column.Width = "150px";
                           if (column.Member == "DocumentId" || column.Member == "IsReadOnly" || column.Member == "IsRed")
                               column.Visible = false;
                       });
                       columns.Command(command =>
                       {
                           command.Custom("viewDetails").Text("Просмотр")
                            .DataRouteValues(route => route.Add(o => o.DocumentId).RouteKey("docId"))
                            .Action("ViewDocumentDetails", "ManagerDocument")
                            .HtmlAttributes(new { style = "text-align: center" });
                       }).Width(50);
                   })

                 .Sortable()
                .Pageable()
                .Filterable()
                )            
<script type="text/javascript">

    function onDocumentListGridRowDataBound(e) {
        if (e.dataItem.IsReadOnly > 0) {
            $(e.row).find('a.t-grid-EditDetails').remove();
            $(e.row).find('a.t-grid-DeleteDetails').remove();
        }
        if (e.dataItem.IsRed > 0) {
            $(e.row).css("color", "red");
        }
    }

    </script>
